package cn.com.nes.site.controller.crm.saleorder;

import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.entity.vo.crm.SalePriceMasterVO;
import cn.com.nes.site.service.crm.order.SalePriceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 报价单（系统单）控制层
 *
 * @Author: ShenWei
 * @Date: 2024/03/15/14:10
 */
@Controller
@RequestMapping("/v2/crm/priceSheet")
public class SalePriceController {
    @Resource
    SalePriceService salePriceService;

    @ApiOperation("查询报价单列表")
    @RequestMapping(value = "/getPriceSheetList",method = RequestMethod.GET)
    public @ResponseBody PageData getPriceSheetList(SalePriceMasterVO vo) {
        return salePriceService.getPriceSheetList(vo);
    }

    @ApiOperation("查询报价单详情")
    @RequestMapping(value = "/getPriceSheetDetail",method = RequestMethod.GET)
    public @ResponseBody PageData getPriceSheetDetail(SalePriceMasterVO vo) {
        if (Objects.isNull(vo.getId())){
            PageData.error("请传入报价单id");
        }
        return salePriceService.getPriceSheetDetail(vo);
    }

    @ApiOperation("添加/修改报价单")
    @RequestMapping(value = "/addPriceSheet",method = RequestMethod.POST)
    public @ResponseBody PageData addPriceSheet(@RequestBody SalePriceMasterVO vo) throws Exception {
        return salePriceService.addPriceSheet(vo);
    }

    /**
     * 复制报价单
     */
    @Deprecated
    @RequestMapping(value = "/copyPriceSheet",method = RequestMethod.POST)
    public @ResponseBody PageData copyPriceSheet(@RequestBody SalePriceMasterVO vo) {
        if (Objects.isNull(vo.getId())){
            PageData.error("请传入报价单id");
        }
        return salePriceService.copyPriceSheet(vo);
    }

    @ApiOperation("删除报价单 - 逻辑删除")
    @RequestMapping(value = "/delPriceSheet",method = RequestMethod.POST)
    public @ResponseBody PageData delPriceSheet(@RequestBody SalePriceMasterVO vo) {
        if (Objects.isNull(vo.getId())){
            PageData.error("请传入报价单id");
        }
        return salePriceService.delPriceSheet(vo);
    }

    @ApiOperation("查询当前用户历史系统名称")
    @RequestMapping(value = "/getHistoryName",method = RequestMethod.GET)
    public @ResponseBody PageData getHistoryName(SalePriceMasterVO vo) {
        return salePriceService.getHistoryName(vo);
    }
}
